﻿using System;
using System.Collections.Generic;
using System.Text;

namespace CommonTool
{
    public class GetHelper
    {

        public static DateTime GetDateTime(string text)
        {
            DateTime rs = DateTime.MinValue;
            DateTime.TryParse(text, out rs);
            return rs;
        }

        public static bool GetBool(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return false;
            }
            switch (text)
            {
                case "true":
                    return true;
                case "1":
                    return true;
                case "false":
                    return false;
                case "0":
                    return false;
            }
            return true;
        }


        public static int GetInt(object obj)
        {
            if (object.Equals(obj,null))
            {
                return 0;
            }
            int rs = 0;
            int.TryParse(obj.ToString(), out rs);
            return rs;
        }
        public static int GetInt(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return 0;
            }
            int rs = 0;
            int.TryParse(text, out rs);
            return rs;
        }

    }
}
